/*
 * @Author: szx
 * @Date: 2021-12-11 12:37:17
 * @LastEditTime: 2021-12-11 13:07:11
 * @Description:
 * @FilePath: \leetcode\900-999\911\911.js
 */
/*
 * @Author: szx
 * @Date: 2021-12-11 12:37:17
 * @LastEditTime: 2021-12-11 12:37:30
 * @Description:
 * @FilePath: \leetcode\900-999\911\911.js
 */
/**
 * @param {number[]} persons
 * @param {number[]} times
 */
var TopVotedCandidate = function (persons, times) {
    this.times = times;
    this.tops = [];

    this.map = new Map();
    this.map.set(-1, -1);
    let top = -1;
    for (let p of persons) {
        this.map.set(p, (this.map.get(p) || 0) + 1);
        if (this.map.get(p) >= this.map.get(top)) {
            top = p;
        }
        this.tops.push(top);
    }
};

/**
 * @param {number} t
 * @return {number}
 */
TopVotedCandidate.prototype.q = function (t) {
    let l = 0,
        r = this.times.length;
    while (l < r) {
        let m = l + ((r - l) >> 2);
        if (this.times[m] <= t) {
            l = m + 1;
        } else {
            r = m;
        }
    }
    console.log(this.tops);
    console.log(this.times[l]);
    return this.tops[l - 1];
};

/**
 * Your TopVotedCandidate object will be instantiated and called as such:
 * var obj = new TopVotedCandidate(persons, times)
 * var param_1 = obj.q(t)
 */
